package com.mtsmda.java8Ex;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/*
 * http://www.tutorialspoint.com/java8/
 * http://habrahabr.ru/post/216431/
 * */
public class BasicExample {
	
	public static void main(String[] args) {
		List<String> names1 = new ArrayList<String>();
		String [] arrayNames = new String[]{"Dima", "Vasya", "Petya", "Iliya", "Artem"};
		addToList(names1, arrayNames);
		
		List<String> footbalClubs = new ArrayList<String>();
		String [] arrayfootbalClubs = new String[]{"Barcelona", "Milan", "Spartak", "Real", "Chelsea"};
		addToList(footbalClubs, arrayfootbalClubs);
		System.out.println(names1);
		new BasicExample().sortStyleJava7(names1);
		System.out.println(names1);
		System.out.println(footbalClubs);
		new BasicExample().sortStyleJava8(footbalClubs);
		System.out.println(footbalClubs);
	}
	
	private static void addToList(List<String> list, String ...strings){
		if(strings != null && strings.length > 0){
			for(int i = 0; i < strings.length; i++){
				list.add(strings[i]);
			}
		}
	}
	
	
	private void sortStyleJava7(List<String> strings){
		Collections.sort(strings, new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				return o1.compareTo(o2);
			}
		});
	}
	
	private void sortStyleJava8(List<String> strings){
		Collections.sort(strings, (s1, s2) -> s1.compareTo(s2));
	}
}